//
//  SelectHouseViewController.m
//  RENTVISITOR
//
//  Created by wonder on 2017/8/25.
//  Copyright © 2017年 UNN. All rights reserved.
//

#import "SelectHouseViewController.h"
#import "RentVieitor.h"
#import "HouseCell.h"



@interface SelectHouseViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>

@end

@implementation SelectHouseViewController {
    
    UICollectionView *_collectionView;
}

- (void)viewWillAppear:(BOOL)animated {
    
    self.navigationController.navigationBar.hidden = YES;
    self.tabBarController.tabBar.hidden = YES;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = BackgroundColor;
    [self creatView];
}

- (void)creatView {
    
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KWidth, 60)];
    headView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:headView];
    
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(15, 30, 10,15 );
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"箭头左"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [headView addSubview:leftBtn];
    
    UIButton * canceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [canceBtn setTitle:@"| 取消" forState:UIControlStateNormal];
    [canceBtn setTitleColor:[Utils colorConvertFromString:@"#101010"] forState:UIControlStateNormal];
    canceBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    CGSize size = [@"| 取消" boundingRectWithSize:CGSizeMake(300, 15) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:canceBtn.titleLabel.font} context:nil].size;
    canceBtn.frame = CGRectMake(KWidth-15-size.width, 30,size.width,15);

    [canceBtn addTarget:self action:@selector(cnaceAction) forControlEvents:UIControlEventTouchUpInside];
    [headView addSubview:canceBtn];
    
    UIButton * allBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [allBtn setTitle:@"全选" forState:UIControlStateNormal];
    [allBtn setTitleColor:[Utils colorConvertFromString:@"#101010"] forState:UIControlStateNormal];
    allBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    CGSize size2 = [@"全选" boundingRectWithSize:CGSizeMake(300, 15) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:allBtn.titleLabel.font} context:nil].size;
    allBtn.frame = CGRectMake(KWidth-22.5-size.width-size2.width, 30,size2.width,15);

    [allBtn addTarget:self action:@selector(allAction) forControlEvents:UIControlEventTouchUpInside];
    [headView addSubview:allBtn];
    
    //分割线
    CALayer *MlineLayer = [CALayer layer];
    MlineLayer.backgroundColor = [[Utils colorConvertFromString:@"#d0d0d0"] CGColor];
    MlineLayer.frame = CGRectMake(0 ,60, KWidth, 1);
    [self.view.layer addSublayer:MlineLayer];
    
    //分割线
    CALayer *HlineLayer = [CALayer layer];
    HlineLayer.backgroundColor = [[Utils colorConvertFromString:@"#d0d0d0"] CGColor];
    HlineLayer.frame = CGRectMake((KWidth-1)/2 ,60, 1, 40);
    [self.view.layer addSublayer:HlineLayer];
    
    NSArray *textArray = @[@"区域",@"租金"];
    for (int i=0; i<textArray.count; i++) {
        
//        UILabel *selectLabel = [[UILabel alloc] init];
//        CGSize size3 = [textArray[i] boundingRectWithSize:CGSizeMake(300, 17) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:selectLabel.font} context:nil].size;
//        selectLabel.font = [UIFont systemFontOfSize:17];
//        selectLabel.textAlignment = NSTextAlignmentCenter;
//        headView.frame = CGRectMake((KWidth/2-size3.width-10)/2+KWidth/2*i, 70, size3.width, 20);
//        selectLabel.textColor = [Utils colorConvertFromString:@"#101010"];
//        [headView addSubview:selectLabel];
        
        UIButton *selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        selectBtn.frame = CGRectMake(KWidth/2*i+10, 70, KWidth/2-20, 20);
        selectBtn.tag = 100+i;
        selectBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [selectBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 50)];
        [selectBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 50, 0, 0)];
        [selectBtn setTitleColor:[Utils colorConvertFromString:@"#101010"] forState:UIControlStateNormal];
        [selectBtn setTitle:textArray[i] forState:UIControlStateNormal];
        [selectBtn addTarget:self action:@selector(selectAction:) forControlEvents:UIControlEventTouchUpInside];
        [selectBtn setImage:[UIImage imageNamed:@"下拉箭头"] forState:UIControlStateNormal];
        [headView addSubview:selectBtn];
        }
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    //    [flowLayout setItemSize:CGSizeMake((MWidth-20)/4, 100)];//设置cell的尺寸
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];//设置其布局方向
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);//设置其边界
    _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 110, KWidth, KHeight-110-40)collectionViewLayout:flowLayout];
    _collectionView.dataSource = self;
    _collectionView.delegate = self;
    _collectionView.showsVerticalScrollIndicator = NO;
    _collectionView.showsHorizontalScrollIndicator = NO;
    _collectionView.backgroundColor = [UIColor clearColor];
    UINib *nib = [UINib nibWithNibName:@"HouseCell" bundle:[NSBundle mainBundle]];
    [_collectionView registerNib:nib forCellWithReuseIdentifier:@"_cell"];
    [self.view addSubview:_collectionView];

//    UILabel *proLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, KHeight-40, KWidth, 40)];
//    proLabel.font = [UIFont systemFontOfSize:16];
//    proLabel.textAlignment = NSTextAlignmentCenter;
//    proLabel.textColor = [Utils colorConvertFromString:@"#f7cf33"];
//    proLabel.text = @"将选中的房源加进商铺";
//    proLabel.backgroundColor = [Utils colorConvertFromString:@"#f7cf33"];
    UIButton *setBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    setBtn.frame = CGRectMake(0, KHeight-40, KWidth, 40);
    setBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [setBtn setTitle:@"将选中的房源加进商铺" forState:UIControlStateNormal];
    [setBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [setBtn setTitleColor:[Utils colorConvertFromString:@"#f7cf33"] forState:UIControlStateHighlighted];
    [setBtn setBackgroundColor:[UIColor colorWithRed:249/255.0 green:105/255.0 blue:39/255.0 alpha:1]];
    [setBtn addTarget:self action:@selector(setAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:setBtn];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 10;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    HouseCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"_cell" forIndexPath:indexPath];
    return cell;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    return CGSizeMake(KWidth, 170);
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(5, 5, 5, 5);//分别为上、左、下、右
}

//将选中的房源放进商铺
- (void)setAction {
    
}

//选择区域和租金
- (void)selectAction:(UIButton *)button {
    
    
}

//取消
- (void)cnaceAction {
    
}

//全选
- (void)allAction {
    
}

- (void)backAction {
    
    [self.navigationController popViewControllerAnimated:YES];
}
@end
